<?php
/**
 * Created by PhpStorm.
 * User: luzhaoyang
 * Date: 2017/5/27
 * Time: 11:29
 * 成就系统
 */
class Commmission_model extends Base_Model
{
    private $_redis;
    public function __construct()
    {
        parent::__construct();
        $this->load->model('redis_model');
        $this->_redis=$this->redis_model->getRedisInstance();
        $this->load->database();
    }

    /**
     * 检验某个问题的被关注数
     */
    public function checkSfqn($qid,$check)
    {
        $num=$this->_redis->sCard('question:'.$qid.'.follows');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某人所有问题的总被关注人数（以独立个人为单位）
     */
    public function checkSallfqn($uid,$check)
    {
        $num=$this->_redis->sCard('user:'.$uid.'.followers');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某人是否关注某个问题
     */
    public function checkFqs($qid,$uid)
    {
        $res = $this->_redis->sIsMember('question:'.$qid.'.follows',$uid);
        $rescode = $res==true?1:0;
        return array('rescode'=>$rescode,'data'=>array());
    }
    /**
     * 检验某人的问题总关注数
     */
    public function checkFqn($uid,$check)
    {
        $num=$this->_redis->sCard('user:'.$uid.'.follows');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某人是否关注某个话题
     */
    public function checkFsubs($subid,$uid)
    {
        $res = $this->_redis->sIsMember('subject:'.$subid.'.follows',$uid);
        $rescode = $res==true?1:0;
        return array('rescode'=>$rescode,'data'=>array());
    }
    /**
     * 检验某人的话题总关注数
     */
    public function checkFsubn($uid,$check)
    {
        $num=$this->_redis->sCard('user:'.$uid.'.subfollows');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某个答案的被赞同数
     */
    public function checkSanrn($aid,$check)
    {
        $num=$this->_redis->bitCount('answer:'.$aid.'.agreesraw');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某人所有答案的总被赞同人数（以独立个人为单位）
     */
    public function checkSallagrn($uid,$check)
    {
        $num=$this->_redis->sCard('user:'.$uid.'.agreers');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某人是否赞同某个答案
     */
    public function checkAgranss($aid,$uid)
    {
        $rescode=$this->_redis->getBit('answer:'.$aid.'.agreesraw',$uid);
        return array('rescode'=>$rescode,'data'=>array());
    }
    /**
     * 检验某人的总赞同答案数
     */
    public function checkAgrn($uid,$check)
    {
        $num=$this->_redis->sCard('user:'.$uid.'.agrees');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某个答案的被收藏数
     */
    public function checkScolln($aid,$check)
    {
        $num=$this->_redis->sCard('answer:'.$aid.'.collects');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某人所有答案的总被收藏人数（以独立个人为单位）
     */
    public function checkSallcolln($uid,$check)
    {
        $num=$this->_redis->sCard('user:'.$uid.'.collecters');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验是某人是否收藏某个答案
     */
    public function checkCollanss($uid,$aid)
    {
        $res = $this->_redis->sIsMember('answer:'.$aid.'.collects',$uid);
        $rescode = $res==true?1:0;
        return array('rescode'=>$rescode,'data'=>array());

    }
    /**
     * 检验某人的总答案收藏数
     */
    public function checkColln($uid,$check)
    {
        $num=$this->_redis->sCard('user:'.$uid.'.collects');
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某人的提问总数
     */
    public function checkSqn($uid,$check)
    {
        $num=$this->db->from('comm_question')->where(array('uid'=>$uid))->count_all_results();
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }
    /**
     * 检验某人的观点总数
     */
    public function checkSansn($uid,$check)
    {
        $num=$this->db->from('comm_answer')->where(array('uid'=>$uid))->count_all_results();
        if ($num<$check) $rescode=0;
        else $rescode=1;
        return array('rescode'=>$rescode,'data'=>array('num'=>$num));
    }

}